#!/usr/bin/env python
# -*- coding:utf8 -*-
import optparse
import socketserver
from conf import settings
from core import server


class ArgvHandler:
    def __init__(self):
        self.op = optparse.OptionParser()
        options, args = self.op.parse_args()

        self.verify_args(options, args)

    def verify_args(self, options, args):
        try:
            cmd = args[0]
            if hasattr(self, cmd):
                func = getattr(self, cmd)
                func()
        except Exception:
            print("must add start")

    def start(self):
        print("the server is working...")
        s = socketserver.ThreadingTCPServer((settings.IP, settings.PORT), server.ServerHandler)
        s.serve_forever()
